package primaryAlgorithm.countAndSay;
/**
 * @Date 2020/03/19
 * @author 王光浩
 * @Thinking 使用递归实现
 */
public class MyMethodTwo {
	public String countAndSay(int n) {
		return recursively("1",n-1);
	}
	private String recursively(String value,int n) {
		if(n==0)return value;
		StringBuilder res=new StringBuilder();
		char ch=value.charAt(0);
		int count=1;
		for(int i=1;i<value.length();i++) {
			if(value.charAt(i)!=ch) {
				res.append(count).append(ch);
				count=1;
			}
			else
				count++;
		}
		res.append(count).append(ch);
		return recursively(res.toString(),n-1);
	}
}
